$(function(){
	var aln =0;
	if(document.documentElement.clientWidth<1200){
		aln =2;
//		document.documentElement.style.fontSize = document.documentElement.clientWidth / 750*100 + 'px';
		document.documentElement.style.fontSize = 750 / 750*100 + 'px';
		$(".phone").on("click",function(){
			$(".nav").slideToggle(300);
		});
		
		if(document.documentElement.clientWidth<750){
			var b =document.documentElement.clientWidth/750;
			var x =$("body").width()*(1-b);
			var y =$("body").height()/2;
			$("body").css({"width":"7.50rem"});
			$("html").css({"transform-origin":"0 0"});
			$("html").css({"transform":"scale("+b+","+b+")"});
			
			$(window).on("scroll",function(ev){
				var ev =ev||window.event;
//				console.log($(window).scrollTop())
				if($(window).scrollTop()+$(window).height()>$("html").height()*b){
					$('html, body').animate({scrollTop: $("html").height()*b-$(window).height()},0);
				}
//				if()
			})
		}
	}else{
		aln =3;
		$(".banner").css({"width":$(window).width()});
	}
	//nav点击换页
	$(".nav").on("click","div",function(){
		window.location.href ="./"+$(this).attr("href");
	});
	//数据请求
	$.ajax({
		url: "/zqedu/rest/doUserLoginstatusController.do?doSave&loginstatus=pc",
		type: "get",
		dataType:"json"
	}).done(function(result){})
	//banner图请求
	$.ajax({
		url: "/zqedu/rest/bannerlistController.do?allBannerlist&id=bannerlist",
		type: "get",
		dataType:"json"
	}).done(function(result){
		console.log(result)
		var data =result.obj;
		var banner ="";
		
		for(var i=0;i<data.length;i++){
			var tmp =data[i];
			banner +='<div class="swiper-slide"><img src="./'+tmp.bannerpath+'"/></div>';
		}
		
		$(".ban .swiper-banner .swiper-wrapper").html(banner);
		
		//banner图初始化
		var banner = new Swiper ('.swiper-banner', {
		    loop: true,
		    autoplay: {
		    	delay:5000,
		    },
		    // 如果需要分页器
		    pagination: {
		      el: '.swiper-banp',
		    },
	
		});
		//鼠标覆盖停止自动切换
		banner.el.onmouseover = function(){
		  	banner.autoplay.stop();
		}
		//鼠标覆盖停止自动切换
		banner.el.onmouseleave = function(){
		  	banner.autoplay.start();
		}
	});
	//就业安置案例
	$.ajax({
		url: "/zqedu/rest/realcaseController.do?doSearch",
		type: "get",
		dataType:"json"
	}).done(function(result){
		console.log(result)
		var data =result.obj;
		var alhtml ="";
		
		for(var i=0;i<data.length;i++){
			var tmp =data[i];
			if(tmp.content){
				var content =tmp.content.length>50?tmp.content.substr(0,50)+"...":tmp.content;
			}
			alhtml +='<div class="swiper-slide"><div><img src="./'+tmp.img+'"/></div><div class="alwz">'+content+'</div></div>';
		}
		
		$(".cjrjyazal .swiper-al .swiper-wrapper").html(alhtml);
		
		
		//就业案例初始化
		var al = new Swiper ('.swiper-al', {
		    loop: true,
		    slidesPerView: aln,
		    centeredSlides: true,
		    spaceBetween: 60,
		    autoplay: {
		    	delay:5000,
		    },
	
		});
		//鼠标覆盖停止自动切换
		al.el.onmouseover = function(){
		  	al.autoplay.stop();
		}
		//鼠标覆盖停止自动切换
		al.el.onmouseleave = function(){
		  	al.autoplay.start();
		}
	});
	
	//合作伙伴
	$.ajax({
		url: "/zqedu/rest/partnersController.do?doSearch",
		type: "get",
		dataType:"json"
	}).done(function(result){
		
		console.log(result)
		var data =result.obj;
		var partnershtml ="";
		
		for(var i=0;i<data.length;i++){
			var tmp =data[i];
			partnershtml +='<a class="co-block clearfix" href="'+tmp.links+'" target="_blank"><div class="co-image" style="background: url(./'+tmp.logo+');"></div><div class="co-name">'+tmp.name+'</div></a>';
		}
		
		$(".cooperation .content-content").html(partnershtml);
		
	});
	
	$(".ksjs").on("click",function(){
		
		if(
			!$(".cbjjsq .content-content [name='qymc']").val()||
			!$(".cbjjsq .content-content [name='qylxr']").val()||
			!$(".cbjjsq .content-content [name='lxrdh']").val()||
			!$(".cbjjsq .content-content [name='ygrs']").val()||
			!$(".cbjjsq .content-content [name='pjnx']").val()
		){
			alert("请输入完整的信息");
			return;
		}
		if (ValidatePhone($(".cbjjsq .content-content [name='lxrdh']").val()) == false) {
         	alert('联系电话格式错误，如果是座机号，请输入“-”');
         	return false;
	   	}
		var ygrs =parseInt($(".cbjjsq .content-content [name='ygrs']").val());
		var pjnx =parseInt($(".cbjjsq .content-content [name='pjnx']").val());
		var data ={
			firmname:$(".cbjjsq .content-content [name='qymc']").val(),
			linkman:$(".cbjjsq .content-content [name='qylxr']").val(),
			contact:$(".cbjjsq .content-content [name='lxrdh']").val(),
			firmnum:ygrs,
			submittime:pjnx
		};
		var jg =(ygrs*1.7/100-0)*pjnx*12;
		alert("您需要缴纳 "+jg/10000+"万元 残保金");
		$.ajax({
			url: "/zqedu/rest/applylistController.do?saveApplyList",
			type: "post",
			dataType:"json",
			data:data
		}).done(function(result){});
		
	});
	
	
	
	function ValidatePhone(val){
	    var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;//手机号码
	    var isMob= /^0?1[3|4|5|8][0-9]\d{8}$/;// 座机格式
	    if(isMob.test(val)||isPhone.test(val)){
	        return true;
	    }
	    else{
	        return false;
	    }
	}
});
